<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('大区会长预订单列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li class="select-time">
                                <label>下单时间：</label>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginCreateTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endCreateTime]"/>
                            </li>
                            <li>
                                <label>大区会长：</label>
                                <input type="text" name="agentName"/>
                            </li>
                            <li>
                                <label>状态：</label>
                                <select name="orderState" th:with="type=${@dict.getType('agent_order_state')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>收货人：</label>
                                <input type="text" name="orderName"/>
                            </li>
                            <li>
                                <label>收货电话：</label>
                                <input type="text" name="orderPhone"/>
                            </li>
                            <li>
                                <label>详细地址：</label>
                                <input type="text" name="orderAddress"/>
                            </li>
                            <li>
                                <label>厂家名称：</label>
                                <input type="text" name="factoryName"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <!--<div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="zsyh:agentorder:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="zsyh:agentorder:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="zsyh:agentorder:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="zsyh:agentorder:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>-->
            <div class="col-sm-12 select-table table-bordered">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
     <th:block th:include="include :: bootstrap-table-export-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('zsyh:agentOrder:edit')}]];
        var removeFlag = [[${@permission.hasPermi('zsyh:agentOrder:remove')}]];
        var orderStateDatas = [[${@dict.getType('agent_order_state')}]];
        var isEnsurePlatformDatas = [[${@dict.getType('zsyh_yesno')}]];
        var prefix = ctx + "zsyh/agentOrder";
        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                //是否导出数据
                showExport: true,
                Icons : 'glyphicon-export icon-share',
                /*mso:{//格式转换，可以转换为excel与word
                    fileFormat:'xlsx', //转换为excel的.xlsx格式文档，适用于Excel2007及以上版本
                    xlsx:{//配置.xlsx文件的单元格内容格式
                        formatId:{
                            numbers:0 //保留小数点后的位数
                        }
                    }
                } ,*/
                //选择导出数据的范围，默认basic：只导出当前页的表格数据；all：导出所有数据；selected：导出选中的数据
                exportDataType: "all",
                //导出文件类型,因为导出png文件时会出现忽略的列也显示；导出PDF文件出现中文乱码的问题，所以根据需要只支持Excel文件类型即可
                //['json', 'xml', 'png', 'csv', 'txt', 'sql', 'doc', 'excel', 'pdf']
                exportTypes: ['excel'],
                // Icons:'glyphicon-export',
                // export: 'glyphicon-export icon-share',
                //导出设置
                exportOptions: {
                    ignoreColumn: [11],  //忽略某一列的索引
                    worksheetName: 'sheet1',  //表格工作区名称
                    // tableName: '总台帐报表',
                    //导出文件的名称
                    fileName: '大区会长预订单'+ Date.now(),
                },
                clickToSelect: true,
                rememberSelected: true,
                detailView: true,
                showFooter: true,
                onExpandRow : function(index, row, $detail) {
                    initChildTable(index, row, $detail);
                },
                modalName: "大区会长预订单",
                columns: [{
                    field : 'Number',
                    title : '序号',
                    align: 'center',
                    width: 20,
                    formatter : function(value, row, index) {
                        var pageSize = $('#bootstrap-table').bootstrapTable('getOptions').pageSize;//通过表的#id 可以得到每页多少条
                        var pageNumber = $('#bootstrap-table').bootstrapTable('getOptions').pageNumber;//通过表的#id 可以得到当前第几页
                        return pageSize * (pageNumber - 1) + index + 1;//返回每条的序号： 每页条数 * （当前页 - 1 ）+ 序号
                    }
                },
                {
                    field: 'id',
                    title: '主键',
                    visible: false
                },
                {
                    field: 'agentName',
                    align: 'center',
                    title: '大区会长'
                },
                {
                    field: 'orderName',
                    align: 'center',
                    title: '收货人'
                },
                {
                    field: 'orderPhone',
                    align: 'center',
                    title: '收货电话'
                },
                {
                    field: 'orderAddress',
                    align: 'center',
                    title: '详细地址'
                },
                {
                    field: 'factoryName',
                    align: 'center',
                    title: '厂家名称'
                },
                    {
                        field: 'orderBeginMoney',
                        align: 'center',
                        title: '预订合计金额',
                        footerFormatter:function (value) {
                            var sumBalance = 0;
                            for (var i in value) {
                                if(value[i].orderBeginMoney != null && value[i].orderBeginMoney != '' && value[i].orderBeginMoney != undefined){
                                    sumBalance += parseFloat(value[i].orderBeginMoney);
                                }
                            }
                            return "总金额：" + sumBalance.toFixed(2);
                        }
                    },
                    {
                        field: 'orderEndMoney',
                        align: 'center',
                        title: '发货合计金额',
                        formatter: function(value, row, index) {
                            debugger;
                           if(row.orderState == '3' || row.orderState == '4'){
                               return row.orderEndMoney;
                           }else{
                               return 0;
                           }

                        },
                        footerFormatter:function (value) {
                            var sumBalance1 = 0;
                            for (var i in value) {
                                if(value[i].orderState == '3' || value[i].orderState == '4'){
                                    if(value[i].orderEndMoney != null && value[i].orderEndMoney != '' && value[i].orderEndMoney != undefined){
                                        sumBalance1 += parseFloat(value[i].orderEndMoney);
                                    }
                                }
                            }
                            return "总金额：" + sumBalance1.toFixed(2);
                        }
                    },
                    {
                        field: 'orderState',
                        align: 'center',
                        title: '状态',
                        formatter: function(value, row, index) {
                            return $.table.selectDictLabel(orderStateDatas, value);
                        }
                    },
                /*{
                    field: 'isEnsurePlatform',
                    title: '平台是否已确认 1是 0否',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(isEnsurePlatformDatas, value);
                    }
                },*/
                    {
                        field: 'createTime',
                        align: 'center',
                        title: '下单时间'
                    },
                {
                    title: '操作',
                    align: 'center',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a style="background-color: #ec7e70;border-color: #ec7e70" class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="viewOrder(\'' + row.id + '\')"><i class="fa fa-edit"></i>查看详情</a> ');
                        if(row.orderState == '0'){
                            actions.push('<a class="btn btn-info btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        }
                        actions.push('<a class="btn btn-primary btn-xs " href="javascript:void(0)" onclick="openAttributeImage(\'' + row.logisticsImg + '\')"><i class="fa fa-search"></i>查看物流凭证</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        initChildTable = function(index, row, $detail) {
            var childTable = $detail.html('<table style="table-layout:fixed"></table>').find('table');
            $(childTable).bootstrapTable({
                url: prefix + "/listChild",
                modalName: "产品规格",
                method: 'post',
                sidePagination: "server",
                contentType: "application/x-www-form-urlencoded",
                queryParams: {
                    mid: row.id
                },
                columns: [
                    {
                        field : 'Number',
                        title : '序号',
                        align: 'center',
                        width: 30,
                        formatter : function(value, row, index) {
                            var pageSize = $('#bootstrap-table').bootstrapTable('getOptions').pageSize;//通过表的#id 可以得到每页多少条
                            var pageNumber = $('#bootstrap-table').bootstrapTable('getOptions').pageNumber;//通过表的#id 可以得到当前第几页
                            return pageSize * (pageNumber - 1) + index + 1;//返回每条的序号： 每页条数 * （当前页 - 1 ）+ 序号
                        }
                    },
                    {
                        field: 'id',
                        title: '主键',
                        align: 'center',
                        visible: false
                    },
                    {
                        field: 'attributeLogo',
                        align: 'center',
                        title: '规格图',
                        formatter: function (value, row, index) {
                            return $.table.imageView(value);
                        }
                    },
                    {
                        field: 'partsName',
                        align: 'center',
                        title: '产品名称'
                    },
                    {
                        field: 'attributeName',
                        align: 'center',
                        title: '规格名称'
                    },
                    {
                        field: 'orderCount',
                        align: 'center',
                        title: '预订数量'
                    },
                    {
                        field: 'orderPrice',
                        align: 'center',
                        title: '预定单价'
                    },
                    {
                        field: 'orderSellCount',
                        align: 'center',
                        title: '发货数量',
                        formatter:function (value, row1, index) {
                            if(row.orderState == '3' || row.orderState == '4'){
                                //已发货
                                return row1.orderSellCount;
                            }else{
                                return 0;
                            }
                        }
                    },
                    {
                        field: 'orderSellPrice',
                        align: 'center',
                        title: '发货单价',
                        formatter:function (value, row1, index) {
                            if(row.orderState == '3' || row.orderState == '4'){
                                //已发货
                                return row1.orderSellPrice;
                            }else{
                                return 0;
                            }
                        }
                    },{
                        field: 'orderBeginMoney',
                        align: 'center',
                        title: '预订合计金额',
                        formatter:function (value, row, index) {
                            return (row.orderCount * row.orderPrice).toFixed(2);
                        }
                    },
                    {
                        field: 'orderEndMoney',
                        align: 'center',
                        title: '发货合计金额',
                        formatter:function (value, row1, index) {
                            if(row.orderState == '3' || row.orderState == '4'){
                                return (row1.orderSellPrice * row1.orderSellCount).toFixed(2);
                            }else{
                                return 0;
                            }
                        }
                    },]
            });
        };

        function viewOrder(id) {
            var url = ctx+"zsyh/agentOrder/viewOrder/"+id;
            layer.open({
                type: 2,
                area: ['1200px', '800px'],
                fix: false,
                //不固定
                maxmin: true,
                shade: 0.3,
                title: "查看详情",
                content:  url,
                closeBtn: 1,
                // 弹层外区域关闭
                shadeClose: true,
                end: function(){
                    //location.reload();
                },
                cancel: function(index) {
                    //location.reload();
                }
            });
        }

        function openAttributeImage(logisticsImg){
            debugger;
            if(logisticsImg != null && logisticsImg!= 'null' && logisticsImg !='' && logisticsImg !=undefined){

                layer.open({
                    type: 2,
                    area: [$(window).width()/1.5 + 'px', ($(window).height() - 50) + 'px'],
                    fix: false,
                    //不固定
                    maxmin: true,
                    shade: 0.3,
                    title: "查看物流凭证",
                    content: logisticsImg,
                    btnClose: 1,
                    // 弹层外区域关闭
                    shadeClose: true,
                    yes: function(index, layero) {
                        debugger;
                        var iframeWin = layero.find('iframe')[0];
                        var imageUrl = layero.find('iframe')[0].contentWindow.$("#imageUrl").val();
                        iframeWin.contentWindow.submitHandler(index, layero);
                    },
                    cancel: function(index) {
                        return true;
                    }
                });
                /*$.modal.open("查看物流凭证", logisticsImg);*/
            }else{
                $.modal.alertWarning("暂无物流凭证");
            }
        }

    </script>
</body>
</html>